#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	vector<vector<int>> highestPeak(vector<vector<int>>& isWater)
	{
		array<int[2], 4> dirs { { { 0, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 } } };
		queue<pair<int, int>> aux;
		int len_row = size(isWater), len_col = size(isWater[0]);
		for (int irow = 0; irow < len_row; irow++)
			for (int icol = 0; icol < len_col; icol++)
				if (isWater[irow][icol] == 1) {
					aux.emplace(irow, icol);
					isWater[irow][icol] = 0;
				}
				else isWater[irow][icol] = 2020;
		int layer_val = 0;
		while (!aux.empty()) {
			int layer = size(aux);
			layer_val++;
			while (layer-- > 0) {
				auto [irow, icol] = aux.front(); aux.pop();
				int& cur = isWater[irow][icol];
				if (layer_val != 0 && cur <= layer_val) continue;
				cur = layer_val;
				for (auto [dx, dy] : dirs) {
					int nrow = irow + dx, ncol = icol + dy;
					if (nrow < len_row && nrow >= 0 && ncol < len_col && ncol >= 0) aux.emplace(nrow, ncol);
				}
			}
		}
		return isWater;
	}

private:
};

int main()
{
	[[maybe_unused]] Solution solution;
	return 0;
}
